namespace ts4 {


    function add(x: number, y: number): number {
        console.log(x + y)
        return x + y;
    }
    let myAdd = function (x: number, y: number): number {
        console.log(x + y)
        return x + y;
    }

    let myAdd2: (x: number, y: number) => number = function (x: number, y: number): number {
        console.log(x + y)
        return x + y;
    }
    let myAdd3: (baseValue: number, increment: number) => number = function (x: number, y: number): number {
        console.log(x + y)
        return x + y;
    }


    const fn = (name: string, age?: number): string => {
        console.log(name + age)
        return name + age

    }
    fn('张三')

    const fn1 = (name: string = '我是默认值'): string => {
        console.log(name)
        return name
    }
    fn1()

    const fn2 = (array: number[], ...items: any[]): any[] => {
        console.log(array, items)
        return items
    }
    let a1: number[] = [1, 2, 3]
    fn2(a1, '4', '5', '6')

    interface Add {
        (num: number, num2: number): number
    }
    const fn3: Add = (num: number, num2: number): number => {
        return num + num2
    }
    console.log(fn3(1, 5))

    interface User {
        name: string;
        age: number;
    }
    function getUser(user: User): User {
        return user
    }


    function fn4(params: number): void
    function fn4(params: string, params2: number): void
    function fn4(params: any, params2?: any): void {
        console.log(params)
        console.log(params2)
    }
    fn4(123)
    fn4('123', 456)
}

